package com.ruoyi.park.service.impl;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.park.domain.BuiGreenRecord;
import com.ruoyi.park.mapper.BuiGreenRecordMapper;
import com.ruoyi.park.service.IBuiGreenRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 绿化记录Service业务层处理
 *
 * @author cjie
 * @date 2021-09-16
 */
@Service
public class BuiGreenRecordServiceImpl implements IBuiGreenRecordService {
    @Autowired
    private BuiGreenRecordMapper buiGreenRecordMapper;

    /**
     * 查询绿化记录
     *
     * @param id 绿化记录ID
     * @return 绿化记录
     */
    @Override
    public BuiGreenRecord selectBuiGreenRecordById(String id) {
        return buiGreenRecordMapper.selectBuiGreenRecordById(id);
    }

    /**
     * 查询绿化记录列表
     *
     * @param buiGreenRecord 绿化记录
     * @return 绿化记录
     */
    @Override
    public List<BuiGreenRecord> selectBuiGreenRecordList(BuiGreenRecord buiGreenRecord) {
        return buiGreenRecordMapper.selectBuiGreenRecordList(buiGreenRecord);
    }

    /**
     * 新增绿化记录
     *
     * @param buiGreenRecord 绿化记录
     * @return 结果
     */
    @Override
    public AjaxResult insertBuiGreenRecord(BuiGreenRecord buiGreenRecord) {
        buiGreenRecord.setId(IdUtil.getSnowflake(0, 0).nextIdStr());
        buiGreenRecord.setCreateTime(DateUtils.getNowDate());
        buiGreenRecord.setCreateBy(SecurityUtils.getUsername());

        if(buiGreenRecordMapper.insertBuiGreenRecord(buiGreenRecord)>0){
            return AjaxResult.success(buiGreenRecord.getId());
        }else{
            return AjaxResult.error();
        }
    }

    /**
     * 修改绿化记录
     *
     * @param buiGreenRecord 绿化记录
     * @return 结果
     */
    @Override
    public int updateBuiGreenRecord(BuiGreenRecord buiGreenRecord) {
        buiGreenRecord.setUpdateTime(DateUtils.getNowDate());
        buiGreenRecord.setUpdateBy(SecurityUtils.getUsername());
        return buiGreenRecordMapper.updateBuiGreenRecord(buiGreenRecord);
    }

    /**
     * 批量删除绿化记录
     *
     * @param ids 需要删除的绿化记录ID
     * @return 结果
     */
    @Override
    public int deleteBuiGreenRecordByIds(String[] ids) {
        return buiGreenRecordMapper.deleteBuiGreenRecordByIds(ids);
    }

    /**
     * 删除绿化记录信息
     *
     * @param id 绿化记录ID
     * @return 结果
     */
    @Override
    public int deleteBuiGreenRecordById(String id) {
        return buiGreenRecordMapper.deleteBuiGreenRecordById(id);
    }
}
